package com.ruoyi.project.mesworkshop.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.project.mesworkshop.service.impl.MesWorkshopServiceImpl;
import com.ruoyi.project.system.domain.SysDictData;
import com.ruoyi.project.system.service.ISysDictTypeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.common.zx.PageData;
import com.ruoyi.project.mesworkshop.service.impl.MesWorkshopLineServiceImpl;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 车间流水线Controller
 *
 * @author zx
 * @date 2023-06-05
 */
@RestController
@RequestMapping("/mes/workshop/line")
public class MesWorkshopLineController extends BaseController {
    @Autowired
    private MesWorkshopLineServiceImpl mesWorkshopLineService;

    @Autowired
    private MesWorkshopServiceImpl mesWorkshopService;





    /**
     * 查询车间流水线列表
     */
    @PreAuthorize("@ss.hasPermi('mes:workshop:line:list')")
    @GetMapping("/list")
    public TableDataInfo list() {
        PageData pd = this.getPageData();
        startPage();
        List<PageData> list = mesWorkshopLineService.selectMesWorkshopLineList(pd);
        return getDataTable(list);
    }


//    @GetMapping(value = "/line/{workshopLine}")
//    public AjaxResult workshopLine(@PathVariable String workshopLine) {
//        PageData pd = this.PageData();
//        workshopLine.setPageData(workshopLine);
//        List<PageData> data = mesWorkshopService.selectMesWorkshop(pd);
//        if (StringUtils.isNull(data)) {
//            data = new ArrayList<PageData>();
//        }
//        List<Map<String, Object>> list = new ArrayList();
//        data.stream().forEach(new Consumer<PageData>() {
//            @Override
//            public void accept(PageData a) {
//                Map<String, Object> map = new HashMap<>();
//                map.put("dictLabel", a.getDictLabel());
//                map.put("dictValue", a.getDictValue());
//                map.put("dictType", a.getDictType());
//                list.add(map);
//            }
//        });
//        return success(list);
//    }


    /**
     * 导出车间流水线列表
     */
    @PreAuthorize("@ss.hasPermi('mes:workshop:line:export')")
    @Log(title = "车间流水线", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PageData pd) {
        List<PageData> list = mesWorkshopLineService.selectMesWorkshopLineList(pd);
        ExcelUtil<PageData> util = new ExcelUtil<PageData>(PageData. class);
        util.exportExcel(response, list, "车间流水线数据");
    }

    /**
     * 获取车间流水线详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:workshop:line:query')")
    @GetMapping(value = "/{workshop_code}")
    public AjaxResult getInfo(@PathVariable("workshop_code") String workshop_code) {
        return success(mesWorkshopLineService.selectMesWorkshopLineByWorkshop_code(workshop_code));
    }

    /**
     * 新增车间流水线
     */
    @PreAuthorize("@ss.hasPermi('mes:workshop:line:add')")
    @Log(title = "车间流水线", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PageData pd) {
        return toAjax(mesWorkshopLineService.insertMesWorkshopLine(pd));
    }

    /**
     * 修改车间流水线
     */
    @PreAuthorize("@ss.hasPermi('mes:workshop:line:edit')")
    @Log(title = "车间流水线", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PageData pd) {
        return toAjax(mesWorkshopLineService.updateMesWorkshopLine(pd));
    }

    /**
     * 删除车间流水线
     */
    @PreAuthorize("@ss.hasPermi('mes:workshop:line:remove')")
    @Log(title = "车间流水线", businessType = BusinessType.DELETE)
    @DeleteMapping("/{workshop_codes}")
    public AjaxResult remove(@PathVariable String[] workshop_codes) {
        return toAjax(mesWorkshopLineService.deleteMesWorkshopLineByWorkshop_codes(workshop_codes));
    }
}
